<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<mat-card class="card">
  <mat-card-content>
    <div class="card__header">
      <div>
        <div class="card__header__title">Details</div>
        <div class="card__header__subtitle">Analyse the connection logs and messages for a specific connection</div>
      </div>
      <a mat-button mat-raised-button [routerLink]="'..'" aria-label="Back to Connections">Back to Connections</a>
    </div>

    <mat-tab-group (selectedTabChange)="onTabChange($event)">
      <mat-tab label="Connection Logs">
        <div *ngIf="connectionLog$ | async as connectionLogDetail; else showEmptyState" class="connection-log">
          <api-runtime-logs-connection-log-details [connectionLogDetail]="connectionLogDetail"></api-runtime-logs-connection-log-details>
        </div>
        <ng-template #showEmptyState>
          <api-runtime-logs-details-empty-state (navigateToSettings)="openLogsSettings()"></api-runtime-logs-details-empty-state>
        </ng-template>
      </mat-tab>
      <mat-tab label="Messages">
        <div *ngIf="messageLogs$ | async as messageLogs" class="messages">
          <ng-container *ngIf="messageLogs.length === 0; else showList">
            <api-runtime-logs-details-empty-state (navigateToSettings)="openLogsSettings()"></api-runtime-logs-details-empty-state>
          </ng-container>

          <ng-template #showList>
            <ng-container *ngFor="let messageLog of messageLogs">
              <api-runtime-logs-message-item
                [messageLog]="messageLog"
                [entrypointConnectorIcon]="connectorIcons[messageLog.entrypoint?.connectorId]"
                [endpointConnectorIcon]="connectorIcons[messageLog.endpoint?.connectorId]"
              ></api-runtime-logs-message-item>
            </ng-container>
          </ng-template>
        </div>
      </mat-tab>
    </mat-tab-group>

    <div class="card__footer" *ngIf="pageIndex <= pageCount && selectedTab === 'Messages'">
      <button mat-button mat-raised-button aria-label="Load 5 more" (click)="loadMoreMessages()">Load 5 more</button>
    </div>
  </mat-card-content>
</mat-card>
